﻿Imports System.Data.OleDb

Public Class AddCar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    Protected Sub btnAddCar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnAddCar.Click
        Dim myGUID As New System.Guid
        myGUID = Guid.NewGuid()
        Dim newFileName = myGUID.ToString() + ".jpg"
        If txtImage.HasFile Then
            Dim FileOnDisk = Request.MapPath("Images") & "/" & newFileName
            txtImage.SaveAs(FileOnDisk)
        End If
        Dim conn As OleDbConnection = New OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql = "INSERT INTO Car (CarModel,CarType,CarColour,CarFuel,CarYear,CarEngine,CarTransmission,CarWheelSize,CarBluetooth,CarNavigation,CarSecurity,CarSunroof,Picture) VALUES (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12,@f13)"
        Dim cmd = New OleDbCommand(sql, conn)

        cmd.Parameters.AddWithValue("@f1", txtCarModel.Text)
        cmd.Parameters.AddWithValue("@f2", txtType.Text)
        cmd.Parameters.AddWithValue("@f3", txtColour.Text)
        cmd.Parameters.AddWithValue("@f4", dropdownFuel.SelectedValue)
        cmd.Parameters.AddWithValue("@f5", txtYear.Text)
        cmd.Parameters.AddWithValue("@f6", txtEngine.Text)
        cmd.Parameters.AddWithValue("@f7", rbTransmission.SelectedValue)
        cmd.Parameters.AddWithValue("@f8", txtWheelSize.Text)
        cmd.Parameters.AddWithValue("@f9", chkBoxBluetooth.Checked)
        cmd.Parameters.AddWithValue("@f10", chkBoxNavigation.Checked)
        cmd.Parameters.AddWithValue("@f11", chkBoxSecurity.Checked)
        cmd.Parameters.AddWithValue("@f12", chkBoxSunroof.Checked)
        cmd.Parameters.AddWithValue("@f13", "Images/" & newFileName)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        Response.Redirect("list.aspx")
    End Sub

    
End Class